Jump to content

<input type="image"


StirCrazy

Recommended Posts

I've attached the basics of the Registration page i'm working with.

My problem is that when when I use <input type="image"
If some of the registation fields are empty and press 'submit' I get an alert but then it refreshes the screen.
I don't want it to refresh (coz I lose all the information already entered).

When I use <input type="button" this doesn't happen.

Does anyone know why it refreshes?

Cheers folks,
S.C>

[code]

<script language="javascript">
  function check_fields(regform) {
    errIndicator = 0;
    for (i = 1; i<11; i++) {
      if ("" == regform.elements[i].value) {
        errIndicator = 1;
      }
    }

    if (errIndicator) {
      alert("Please fill in all fields");
      return 1;
    }

    if (regform.email.value != regform.email2.value) {
      alert("E-Mail Confirmation Failed");
      return 3;
    }

    if (regform.country.value == "no") {
      alert("You must choose your country");
      return 4;
    }
   
    if (regform.agree.checked == false ){
alert('Please accept our Terms of service to continue.');
  return 5;
}

    regform.submit();

    return 0;
  }
</script>

<form name="regform" action="index.php?page=register3" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div align="center">




<!------- CODE HERE --------->




<br><center><span class="AcceptTos">
I certify that <b>I am a U.K. Resident over the age of 18, and<br>
I agree to the</b> <a class="AcceptTos" href="javascript:popup('tos.php')">Terms of Service</a>: <input type="checkbox" value="0" name="agree"></span>
<br>
<br>
<input type="image" src="images/layout/submit.gif" onclick="check_fields(regform);" value="  Sign Up  "></center>
<br>
</form>

</div>

<?php
  return(0);
}

[/code]
Link to comment
Share on other sites

<input type="image"> acts as a submit button, so when you click on it, the form is being immediately submitted.  You could try just using an <img>, with the same onClick parameter as your <input type="image"> OR you could change

onclick="check_fields(regform);"

to

onclick="check_fields(regform); return false;"

and leave it where it is.  Either should work fine.

Hope that works for you.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.