Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

JavaScript Text box value move to list box

views
     
TSangie_oet
post Apr 11 2008, 03:55 PM, updated 16y ago

New Member
*
Junior Member
15 posts

Joined: Dec 2006


Dear all,
Do you have any idea on move a text box value to list box.
Store text box value into list box and I wish to save list box value to database.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>add to dropdown</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
window.onload=function() {
document.forms['form1'].fruit.onblur=function(){addToDD(this.value);};
}
function addToDD(val) {
var oSelect=document.forms['form1'].select1;
oSelect.options[oSelect.options.length]=new Option(val, val);
document.forms['form1'].fruit.value="";
}
</script>
</head>
<body>
<form action="#" name="form1">
<fieldset><legend>add to dropdown</legend>
<select name="select1">
<option>apple</option>
<option>banana</option>
<option>cranberry</option>
</select>
<label>add text: <input type="text" name="fruit"></label>
</fieldset>
</form>
</body>
</html>

Example found in Internet. I do not think this will work because after refresh, all value in drop down has gone. Isn't I need to include $_SESSION['arr'] = array();
$_SESSION['arr'][] = $_POST['text_name'];

Language: php and javascript

Please advise. Thanks.
xlancer
post Apr 11 2008, 04:27 PM

Enthusiast
*****
Senior Member
785 posts

Joined: May 2007


did u try, dun submit the form?
onclick run javasrcipt that add to dropdownlist.

This post has been edited by xlancer: Apr 11 2008, 04:27 PM
sunsuron
post Apr 11 2008, 05:51 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



There are many ways to do this. At http://www.socmedia.com.my/lowyat/angie_oet/angie_oet.phps I am using jQuery library to bind 'onBlur' event at the text input and fire xmlhttprequest to the server and refresh the page. This example might not what you want. Just to show you one of thing that we can do. The easiest or straightforward way is just submit the form everytime onlur event occurred at the text input.

 

Change to:
| Lo-Fi Version
0.0140sec    0.27    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 07:30 PM