Menu
thought this would be easier, but i guess not. all i want to do is click on a link, and call a function that fills in <input type=’text’> in a form. I seached, couldn’t find what i needed. Heres what i have so far:
<script name=”javascript”>
function preview(policyid){
document.patientedit.idnumber.value=policyid
//alert(policyid);
}
</script>
<form name=’patientedit’ action=’patupdate.php’ method=’post’>
<table>
<tr>
<td>
<input type=’text’ name=’idnumber’ value='”.$idnumber.”‘>
</td>
</tr>
<tr>
<td>
<a style=’cursor:hand’ onclick=”preview(‘”.$policy_id.”‘)”>fill in text box</a>
</td>
</tr>
</table>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
<script type="text/javascript">
<!--
function preview (policyid) {
document.patientedit.idnumber.value = policyid
}
// -->
</script>
<style type="text/css">
<!--
fieldset {padding:1em; width:10em}
label {display:block}
-->
</style>
</head>
<body>
<form name="patientedit" action="patupdate.php" method="post">
<fieldset>
<label>ID Number <input type="text" name="idnumber" value=".$idnumber."></label>
<a style="cursor:hand" onclick="preview('.$policy_id.')">fill in text box</a>
</fieldset>
</body>
</html>
well i have myself to blame. I have the code in the <body>, only works in the <head>. the thing that threw me off was that the alert works in the body...Then you are doing something terribly wrong. A script works anywhere. Is it possiible that you have droped a tag?
sorry to waste our time![/QUOTE]
well while were on the subject, how do i check a checkbox when they all have the same name? [/QUOTE]They shouldn't have the same name. You can, however, address all a form's elements as elements of an array just like each form is an element of an array: [font=monospace]document.forms[0].elements[3].checked[/font]
droped a tag? not sure what you mean.
notice my form has 7 checkboxes all with: name='ctype'
is that a problem?
i have this at the top of my page:
<?xml version='1.0' encoding='iso-8859-1' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd ">
<html xmlns="http://www.w3.org/1999/xhtml ">
<head>
any example you can provide will be fine, i can change the "escapes" if i have to, thanks in advance.[/QUOTE]
Names should be unique, like IDs. You can reference all of them via the elements array.[/QUOTE]Not necessarily. Actually, for radio buttons, names are the same so they work as a group. That is the purpose for DOM's document.getElementsByName, which returns a HTMLCollection. However, for unique elements, your point is well taken.
thanks for the help charles. ok, ill will do the reading and try to validate my stuff better. But for now, anybody have a solution? should i change the name of each checkbox?Perhaps if you more clearly and more fully explaind just what it is that you are up to we could be of more help.
if i do change the name of each checkbox, how do i set it as check dynamically?
document.patientedit.checboxname. < not sure what goes here...[/QUOTE]
if (document.patientedit.checboxname.checked) {alert ('Yes, it's checked') else {alert ('No, it's not')}
document.patientedit.checboxname.checked = true
<i>
</i> function check(input,value){
for(var i=0; i<input.length; i++){
if(input[i].value.match(value)){
input[i].checked = true;
}
}
}
// EXAMPLE USAGE:
onclick="check(this.form.ctype,'feca')"
document.patientedit.selectname.options[document.patientedit.selectname.selectedIndex].value
<script type="text/javascript">
<!--
function checkOut (theForm) {
if (theForm.selectname.options[theForm.selectname.selectedIndex].value == '') return false [i]// to stop the form from submitting [/i]}
// -->
<form action="some-script.pl" onsubmit="return checkOut (this)">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
<script type="text/javascript">
<!--
onload = function () {
document.getElementById ('month').selectedIndex = new Date().getMonth()
}
// -->
</script>
</head>
<body>
<div>
<select id="month">
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
</body>
</html>
0.1.9 — BETA 5.18