How can I let or not a send with Get method

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
nasix
Forum Newbie
Posts: 6
Joined: Wed Aug 16, 2006 11:16 am

How can I let or not a send with Get method

Post by nasix »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have an input text and a hyperlink, so before sending (with the Get method using the hyperlink) I want to check the text given en the input text, if Ok I send data, else I show an error message and I don't send the data, 

example:

[syntax="html"]
<script language="javascript">
function AddDataToLink(){
   if(document.getElementById('data').value == ''){
        alert('No data to send');
   }
   else{
        document.getElementById('link').href = "index.php?data=' "+document.getElementById('data').value+" ' ";
   }
}
</script>

<form ...>
<input type=text id='data' name=data>

</form>

<a href='index.php' id='link' onClick='AddDataToLink();'>send</a>
the problem here is that the data is sent in all cases. the thing I want is to not send data in the first case (if data=='')

thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

if(data == '')
{
   return false;
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Javascript != PHP :?

Moved.
User avatar
nasix
Forum Newbie
Posts: 6
Joined: Wed Aug 16, 2006 11:16 am

Post by nasix »

Ok return false,

thanks,
Post Reply