Forum Moderators: open
how do i do it?
( I tried calling a function like this:
onKeyPress="changeVal()" and in the function wrote
function changeVal(){
<?php if(is_numeric($_GET['usage'])){?>
myForm.myText.value = "" ;
<?php }?>
}
However its obviously wrong and says "error on page" in the bottom of the page...
I understand that php is server side and javascript is client side but i m so confused ..
please help!
Thanks
Parse error: parse error, unexpected '<' in c:\program files\easyphp1-7\www\mysite\css_test\try.php on line 8
The line 8 is:
<input type="text" onKeyDown="var lilKey=event.keyCode; if(lilKey==48){return true} else if(lilKey >=49&&lilKey<=57){return true}else{alert('Numbers only!');return false;}">
<html>
<body>
<input type="text" id="usage" onkeyup="checkField(this);">
</body>
<script language="javascript">
function checkField(object) {
var regex = /^\d$/;
if (!regex.test(object.value)) {
object.value = "";
} // end if
} // end function
</script>
</html>
The moment the user selects usage without first selecting a project he should be reminded to select project first ....how do i do that?
<html>
<body>
<input type="text" id="usage" onkeydown="return checkField(this);">
</body>
<script language="javascript">
function checkField(object) {
if (event.keyCode < 48 ¦¦ event.keyCode > 57 ¦¦ document.getElementById("usage").value.length == 3) {
return false;
} // end if
return true;
} // end function
</script>
</html>
<html>
<body>
<table>
<tr>
<td>project:</td>
<td>
<select name="project" id="project" size="1">
<option value="">Please choose an option</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
</tr>
<tr>
<td>usage:</td>
<td><input type="text" name="usage" id="usage" onkeydown="return checkField(this);"></td>
</tr>
</body>
<script language="javascript">
function checkField(object) {
if (document.getElementById("project").selectedIndex == 0) {
alert("Attention:\r\rPlease choose a project first");
return false;
} else if (event.keyCode!= 8 && (event.keyCode < 48 ¦¦ event.keyCode > 57 ¦¦ document.getElementById("usage").value.length == 3)) {
return false;
} // end if
return true;
} // end function
</script>
</html>
There is a hitch. The drop down menus are dynamically generated depeding on some options that user selects. As a result there are several project drop down menus with the id=project . So its like
Project Usage
Project Usage
Project Usage
even if i select a project , i get the alert bcos every other project menu is not selected ....so what do i do to get the right alert n prevent others?
<html>
<body>
<form name="frmOne" id="frmOne">
Form One
<select id="cmbTest" name="cmbTest" size="1">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
<form name="frmTwo" id="frmTwo">
Form Two
<select id="cmbTest" name="cmbTest" size="1">
<option value="3">3</option>
<option value="4">4</option>
</select>
<br>
<input type="button" value="Check Form One Value" onclick="checkFormOne();">
<br>
<input type="button" value="Check Form Two Value" onclick="checkFormTwo();">
</form>
</body>
<script language="javascript">
function checkFormOne() {
var obj = document.all.frmOne.all.cmbTest
alert(obj.options[obj.selectedIndex].value);
} // end function
function checkFormTwo() {
var objArray = document.getElementById("frmTwo").getElementsByTagName("SELECT");
var obj;
for (var i = 0;i < objArray.length;i++) {
if (objArray[i].id == "cmbTest") {
obj = objArray[i];
break;
} // end if
} // end for
alert(obj.options[obj.selectedIndex].value);
} // end function
</script>
</html>