Click to See Complete Forum and Search --> : is this possible
2 peachy
05-19-2003, 07:56 PM
I have set my cookie problem aside for a while....
is it possible to get information a user puts in a form, and when the user clicks on submit .. they get an alert popup with the information they put into the form on it ?
hope I explained it right
Sure, as a simple demo, try this:
<html>
<head>
<title>Alert Form Values</title>
<script language="javascript" type="text/javascript">
function showForm(frm) {
alert(frm.mytext01.value+"\n"+frm.mytext02.value);
}
</script>
</head>
<body>
<form name="myform" onsubmit="showForm(this);">
<input type="text" name="mytext01"/>
<input type="text" name="mytext02"/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
2 peachy
05-19-2003, 08:17 PM
will it work with check boxes where they can choose only one and it will display the choice they made ?
like with this example form ?
<form name="f">
<select size=1 MULTIPLE name="lstURL">
<OPTION value="1">Item 1
<OPTION value="2">Item 2
<OPTION value="3">Item 3
<OPTION value="4">Item 4
</select>
<input type="submit" value="submit">
</form>
2 peachy
05-19-2003, 08:19 PM
oops I meant menu list and user can choose only one
That would be done something like this:
<html>
<head>
<title>Alert Form Values</title>
<script language="javascript" type="text/javascript">
function showForm(frm) {
var opts = "";
for (i=0; i<frm.furl.options.length; i++) {
if (frm.furl.options[i].selected) {
opts += "Values Selected: "+frm.furl.options[i].value+"\n";
}
}
alert (opts);
return false;
}
</script>
</head>
<body>
<form name="myform" onsubmit="return showForm(this);">
<select size=1 multiple="multiple" name="furl">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
<option value="4">Item 4</option>
</select>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
2 peachy
05-19-2003, 08:37 PM
Thankyou soooooooo much... that works perfectly...
Charles
05-19-2003, 09:21 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<style type="text/css">
label {display:block}
</style>
<form action="">
<div>
<label><input type="checkbox" value="1" name="url">Item 1</label>
<label><input type="checkbox" value="2" name="url">Item 2</label>
<label><input type="checkbox" value="3" name="url">Item 3</label>
<label><input type="checkbox" value="4" name="url">Item 4</label>
<input type="submit">
</div>
</form>
<script type="text/javascript">
<!--
f = document.forms[document.forms.length-1]
f.onsubmit = function () {
var checked = new Array();
for (j=0; j<f.url.length; j++) {if (f.url[j].checked) checked.push(f.url[j].value)};
child = window.open ('','', 'height=185,width=300');
child.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">');
child.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
child.document.write('<title>Report</title>');
child.document.write('<p>The following values are being submitted.</p>');
child.document.write('<dl>')
child.document.write('<dt>url</dt>');
for (j=0; j<checked.length; j++) {child.document.write('<dd>', checked[j], '</dd>')};
child.document.write('</dl>');
child.document.close();
}
// -->
</script>
Just keep in mind that a good one in ten users do not use JavaScript so you need to keep your pages working for those good people. In this case though, the JavaScript is just fluff. The page will work just fine without it.
2 peachy
05-19-2003, 10:10 PM
thankyou for your help Charles... sorry it took me so long to thank you, had to take a dinner break.