Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 22-07-2009
Member
 
Join Date: Oct 2008
Posts: 47
Help me with onChange javascript event for php form

Hi,

I want some help from you guys regarding the javascript onChange event for my PHP website.
I have a form in a iframe & I want to refresh the page once the user fills the form & clicks the submit button I want him to take to a different URL & the form will be reloaded for next details.

I want your help regarding the onChange event to do the same.
A sample of a working onChange javascript event will also do.

Thanks,
Brake Fail
Reply With Quote
  #2  
Old 22-07-2009
Member
 
Join Date: May 2008
Posts: 248
Re: Help me with onChange javascript event for php form

Data Validation via an onChange event Handler

Code:
<HTML>
<HEAD>
<TITLE>Text Object Select/Focus</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function isNumber(inputStr) {
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.substring(i, i + 1)
        if (oneChar < "0" || oneChar > "9") {
            alert("Please make sure entries are numbers only.")
            return false
        }
    }
    return true
}
function checkIt(form) {
    inputStr = form.numeric.value
    if (isNumber(inputStr)) {
        // statements if true
    } else {
        form.numeric.focus()
        form.numeric.select()

}
}
</SCRIPT>
</HEAD>
<BODY onSubmit="checkIt(this); return false">
<FORM>
Enter any positive integer: <INPUT TYPE="text" NAME="numeric"
 onChange="checkIt(this.form)"><P>
</FORM>
</BODY>
</HTML>
Reply With Quote
  #3  
Old 22-07-2009
Member
 
Join Date: Apr 2008
Posts: 44
Re: Help me with onChange javascript event for php form

onChange Validation:

To force the browser to check each field immediately, we add an onChange to each of the <input> tags in the form.

For example: if we wanted to check if the value of a certain text field had a valid e-mail address we would add this:

Code:
<input type="text" name="Email" size="20" onChange="emailvalidation(this,'The E-mail is not valid');">
onSubmit Validation

You might prefer to check all fields at one time when the user hits the submit button. To do this you should add an onSubmit event handler to the <form>tag.
If this function was called "formvalidation()" the <form> tag would look like this:
Code:
<form onsubmit="return formvalidation(this)">
The function that checks the entire form will either return a value of false or true. If it's true the form will be submitted - if it's false the submission will be cancelled. A script that checks all fields in a form could look like this:

function formvalidation(thisform)
This function checks the entire form before it is submitted.

Code:
function formvalidation(thisform)
{
with (thisform)
{
if (emailvalidation(Email,"Illegal E-mail")==false) {Email.focus(); return false;};
if (valuevalidation(Value,0,5,"Value MUST be in the range 0-5")==false) {Value.focus(); return false;};
if (digitvalidation(Digits,3,4,"You MUST enter 3 or 4 integer digits","I")==false) {Digits.focus(); return false;};
if (emptyvalidation(Whatever,"The textfield is empty")==false) {Whatever.focus(); return false;};
}
}
Reply With Quote
  #4  
Old 22-07-2009
Member
 
Join Date: Oct 2008
Posts: 47
Re: Help me with onChange javascript event for php form

Thanks for the prompt reply ill try out the suggestion again.
It will be better if you help me with php form example.

Thanks again for the link.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Help me with onChange javascript event for php form"
Thread Thread Starter Forum Replies Last Post
Calendar javascript in a JSP form technika Software Development 4 22-02-2010 07:10 PM
How to Submit a Form Using JavaScript? Damien25 Software Development 4 07-02-2010 07:05 AM
How to set the value of a form element using Javascript? shivendra Software Development 4 07-02-2010 05:04 AM
How to use Form Validation in JavaScript? Dilbert Software Development 4 30-01-2010 08:30 PM
Php form with javascript Solaris Software Development 3 30-11-2009 02:22 PM


All times are GMT +5.5. The time now is 11:14 PM.