/    Sign up×
Community /Pin to ProfileBookmark

I need a little help with this javascript of mine.

Hi guys. I’m a newbie here…

I hope you can help me. I want to place a specific Id name to every item that its created by the add script. And i dont know what to do next

got this code from another tutorial site. I just edited it to be used for my own purpose.

here it is…
var inputs = 0;
function add(){
var table = document.getElementById(‘contacts’);

var tr = document.createElement(‘TR’);
var td1 = document.createElement(‘TD’);
var td2 = document.createElement(‘TD’);
var td3 = document.createElement(‘TD’);
var td4 = document.createElement(‘TD’);
var td5 = document.createElement(‘TD’);
var inp1 = document.createElement(‘INPUT’);
var inp2 = document.createElement(‘INPUT’);

if(inputs>=0){
var img = document.createElement(‘IMG’);
img.setAttribute(‘src’, ‘delete.gif’);
img.onclick = function(){
removeOrder(tr);
}
td5.appendChild(img);
}

inp1.setAttribute(“Name”, “Quantity” +inputs);
inp2.setAttribute(“Name”, “Item”+inputs);

table.appendChild(tr);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.appendChild(td4);
tr.appendChild(td5);
td1.appendChild(inp1).style.width = 85;
td3.appendChild(inp2).style.width = 485;
td3.appendChild(inp2).value = myform.mymenu.options[myform.mymenu.selectedIndex].value;
inputs++;

}

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 19.2006 — img.setAttribute('src', 'delete.gif');[/quote]There's an example, you set the "id" the same way you set any other attribute.
Copy linkTweet thisAlerts:
@djwakzauthorAug 19.2006 — hi Charles,

I been searching around i found some scripts..

  • 1. setAttributes ('id', 'name');

  • 2. input.id = 'id';


  • i've used the 2nd one. but every item i click on add... no value display on the created input item.

    The reason why i need to set the id name of every created input item coz i need them to get to my mail using asp.

    i got stuck in a corner
    Copy linkTweet thisAlerts:
    @CharlesAug 19.2006 — You really should set the "name" attribute of Form control elements, not the "id" but the method is the same.

    Ok, lets see. You have two ways of setting the attribute. One you know doesn't work and further somebody has sugested that the other one does. Ergo...
    ×

    Success!

    Help @djwakz spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...