/    Sign up×
Community /Pin to ProfileBookmark

Making selct options with JAVA

Good day,

I have a table with three input fields wich is created with java. I want one of the inputs to be a <select> box with options.
The <select> box is made and visible, but i don’t know how to create the options.
Can someone please advice?

JAVA code:

[CODE]var inputs = 1;
function addrow(){
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 inp1 = document.createElement(‘INPUT’);
var inp2 = document.createElement(‘INPUT’);
var inp3 = document.createElement(‘SELECT’);

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

inp1.setAttribute(“Name”, “vare” +inputs);
inp2.setAttribute(“Name”, “størrelse” +inputs);
inp3.setAttribute(“Name”, “antall” +inputs);

table.appendChild(tr);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.appendChild(td4);
td2.appendChild(inp1);
td3.appendChild(inp2);
td4.appendChild(inp3);

inputs++;
}
function removeContact(tr){if(confirm(‘Delete?’));
else(cancel);
tr.parentNode.removeChild(tr);

}[/CODE]

HTML code:

[CODE]<table>
<tbody id=”contacts”>

<tr>
<td colspan=”3″><a href=”javascript:addrow();”>Add to list</a></td>
</tr>
<tr>
<td>Slett</td>
<td>Vare nummer</td>
<td>Størrelse</td>
<td>Antall</td>
</tr>
</tbody>
</table>[/CODE]

-morten

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsJul 09.2006 — [URL]http://www.webdeveloper.com/forum/showthread.php?t=112787[/URL]
Copy linkTweet thisAlerts:
@the_treeJul 09.2006 — Doesn't it already point out all over the place that that doesn't even look like Java?
Copy linkTweet thisAlerts:
@mortenauthorJul 09.2006 — Yeah, i've read that thread, but that one have a <select> tag in HTML. Since my inputs are created on the fly i need the options to be integrated in the process of creating the the TD.(whatever that means).

Here is the complete document:
[CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>Untitled</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<script language="javascript">
var inputs = 1;
function addrow(){
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 inp1 = document.createElement('INPUT');
var inp2 = document.createElement('INPUT');
var inp3 = document.createElement('INPUT');

if(inputs>0){
var img = document.createElement('IMG');
img.setAttribute('src', 'delete.gif');
img.onclick = function(){
removeContact(tr);
}
td1.appendChild(img);
}

inp1.setAttribute("Name", "vare" +inputs);
inp2.setAttribute("Name", "beskrivelse" +inputs);
inp3.setAttribute("Name", "pris" +inputs);

table.appendChild(tr);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.appendChild(td4);
td2.appendChild(inp1);
td3.appendChild(inp2);
td4.appendChild(inp3);

inputs++;
}
function removeContact(tr){if(confirm('Slette?'));
else(cancel);
tr.parentNode.removeChild(tr);

}
</script>
<body>
<table>
<tbody id="contacts">
<tr>
<td colspan="3"><a href="javascript:addrow();">Legg til vare</a></td>
</tr>
<tr>
<td></td>
<td>vare nummer</td>
<td>beskrivelse</td>
<td>pris</td>
</tr>
</tbody>
</table>

</body>
</html>[/CODE]

If i change:var inp3 = document.createElement('INPUT');

to:var inp3 = document.createElement('SELECT');

then i have the box. But it's empty ?

How can i fill in the options i need?
Doesn't it already point out all over the place that that doesn't even look like Java?[/QUOTE]

Hehe, that does'nt really help. Other then implying i should be posting in a different thread.. If it's not JAVA, what is it then??

-morten
Copy linkTweet thisAlerts:
@vwphillipsJul 09.2006 — inp3 has a select tag so add the options to that.


[CODE]If it's not JAVA, what is it then??[/CODE]

JavaScript
Copy linkTweet thisAlerts:
@mortenauthorJul 09.2006 — Thank you, but i'm not that smart :p

I have tried putting in alot of different commands, with the best result: that nothing changed.... That was the BEST result.

Would you please help me with the format?

i am quite clear that i have to play with inp3, i just don't know how to put in the correct string.

-morten
Copy linkTweet thisAlerts:
@mortenauthorJul 09.2006 — I am surprised!

The thread you linked to was actually applicable to my problem!

I just had to type in all possible wrong combinations first, but i got it to work!

Thank you all ?

-morten
×

Success!

Help @morten 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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