Re: Re: Submit a form with a link
| From: | Justin French | Date: | Tue, 29 Apr 2003 23:55:22 +0000 |
| Subject: | Re: Re: Submit a form with a link | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145716@lists.php.net to get a copy of this message | ||
on 30/04/03 4:25 AM, shaun (shaun@mania.plus.com) wrote:
> but how can i check whether the users browser has javascript enabled?
You can't really, but you CAN provide both solutions within one script using
<NOSCRIPT>. I'm a little rusty on my JS (I barely ever use it on sites),
but theorectically, you want the <SCRIPT> tag to write the link out for you
if possible, otherwise you want the <NOSCRIPT> tag to do so.
From what I can tell, you wanted to use a text link instead of a HTML button
to submit a form.
<form>
First Name: <input type="text" name="firstname" value="">
Surname: <input type="text" name="surname" value="">
<input type="hidden" name="userHasJS" value=1>
<script language="text/javascript">
document.writeln("<a
href='javascript:submitMyForm()'>submit</a>");
</script>
<noscript>
<input type="hidden" name="userHasJS" value=0>
<input type="submit" name="submit" value="submit">
</noscript>
</form>
I've also included a hidden value of userHasJS, which starts as true, and
gets overwritten by false IF the NOSCRIPT tag is in use.
This means you could (on the next page) assign to a session variable, and be
able to test if the user has JS available on any page, by checking the
session var.
Sure, it's a few extra lines of code, but the results will be the best you
could hope for, to the best of my knowledge.
I used to use something similar with pop-ups... If the user had JS, I'd do a
pop-up, otherwise I'd just use <a ... target="_blank">.
Justin French