Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-30-2009, 01:39 PM   PM User | #1
Snitz
Regular Coder

 
Join Date: Jul 2004
Location: Lebanon
Posts: 223
Thanks: 6
Thanked 0 Times in 0 Posts
Snitz is an unknown quantity at this point
Validation redirection error

I'm facing a validation error, whenever I leave any of the fields blank, it gives me a warning and then it redirects me to (index.php?option=com_ccnewsletter&view=ccnewsletter)

What I wanna know is how can I freeze the page until all fields are filled?

This is the javascript code:
Code:
	<script type="text/javascript">
	function formsubmit(task)
	{
		var form = document.subscribeFormModule;
		if(task == "addSubscriber")
		{
			if(form.name.value== "")
			{
				alert('<?php echo $parameters['namewarning']; ?>');
			}
			else if(form.email.value == "")
			{
				alert('<?php echo $parameters['emailwarning']; ?>');
			}
			else if(( form.email.value.search("@") == -1) || ( form.email.value.search("[.*]" ) == -1 ))
			{
				alert('<?php echo $parameters['emailwarning']; ?>');
			}

			<?php if($parameters['showterm'])
			{
			?>
			else if(form.terms_condition_ch.checked == false)
			{
				alert ('<?php echo $parameters['terms_cond_warn']; ?>');

			}
			<?php
			}
			?>

			else
			{
				form.task.value = "addSubscriber";
				form.submit();
			}
		}
		else if(task == "removeSubscriberByEmail")
		{
			if(form.email.value == "")
			{
				alert('<?php echo $parameters['emailwarning']; ?>');
			}
			else if(( form.email.value.search("@") == -1) || ( form.email.value.search("[.*]" ) == -1 ))
			{
				alert('<?php echo $parameters['emailwarning']; ?>');
			}
			else
			{
				form.task.value = "removeSubscriberByEmail";
				form.submit();
			}
		}
	}
	</script>
And this is the form's code:
Code:
<div class="mainnewsletter">
		<p><?php echo $parameters['introduction'] ?></p>
        <div class="module" style="padding-top: 0px;">
		<div class="normalsublayout">
		<form class="form-login" action="<?php echo JRoute::_('index.php?option=com_ccnewsletter&amp;view=ccnewsletter');?>" method="post" name="subscribeFormModule" id="subscribeFormModule">
			<p><div>
			<?php echo $parameters['name']; ?>:
            <div class="username-block">
            <div class="input-field-l">
            <input class="inputbox" type="text" onblur="if(this.value=='') this.value='YourName';" onfocus="if(this.value=='YourName') this.value='';" name="name" id="name" value="<?php echo $name; ?>" />
			</div></div>
			</div>
			</p>
			<p>
			<div>
			<?php echo $parameters['email']; ?>:
            <div class="password-block">
			<div class="input-field-l">
            <input class="inputbox" type="text" onblur="if(this.value=='') this.value='youremail@domain.com';" onfocus="if(this.value=='youremail@domain.com') this.value='';" name="email" id="email" size="15" maxlength="35" value="<?php echo $email; ?>" />
			</div>
			</div>
			</div>
			</p>
			<?php if($parameters['showterm'])
			{
			?>
			<p>
			<input id="ccnewsletter" name="terms_condition_ch" class="inputbox" type="checkbox">
			<a style="font-size:14px;color:#4E4E51; display: margin:0px 0px 0px 5px;text-decoration:none;" href='<?php echo $cid; ?>' class="modal" rel="{handler: 'iframe', size: {x: 700, y: 375}}"><?php echo $terms;?></a>
			</p>
			<?php
			}
			if($unsubscribe)
			{
			?>
			<p>
				<input class="button" type="submit" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber');"/>
          </p>
				<p><input class="button" type="submit" id="removeSubscriberByEmail" name="removeSubscriberByEmail" value="<?php echo $parameters['unsubscribe']; ?>"  onclick="formsubmit('removeSubscriberByEmail');"/>
			</p>
			<?php
			}
			else
			{
			?><div class="readon-wrap1">
<div class="readon1-l"></div>
<span class="readon-main"><span class="readon1-m"><span class="readon1-r"><input class="button" type="submit" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber');"/></span></span></span></div>
				
				<!--<p><center><input  type="image" src="images/back_f2.png" id="addSubscriber" name="addSubscriber" value="<?php echo $parameters['subscribe']; ?>"  onclick="formsubmit('addSubscriber');"/></center></p>-->
			<?php
			}
			?>
			<input type="hidden" name="option" value="com_ccnewsletter" />
			<!--<input type="hidden" name="task" value="addSubscriber" />-->
			<input type="hidden" name="task" value="" />
			</form>
		</div>
	</div></div>
I don't know, maybe I'm missing something because it was working fine a before.
Snitz is offline   Reply With Quote
Old 12-30-2009, 01:59 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Please post a link to your page or the parsed output taken from browser's "view source" option.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 12-30-2009, 03:33 PM   PM User | #3
Snitz
Regular Coder

 
Join Date: Jul 2004
Location: Lebanon
Posts: 223
Thanks: 6
Thanked 0 Times in 0 Posts
Snitz is an unknown quantity at this point
Unfortunately I'm working on localhost, so here's the "view source" code.
It's a bit long because I'm using joomla.

The code of the newsletter starts from
Code:
<div class="module-header"><div class="module-header2"><div class="module-header3"><h3 class="module-title">Newsletter </h3></div></div></div>
Thanks for your help.
Attached Files
File Type: txt newsletter.txt (48.0 KB, 110 views)
Snitz is offline   Reply With Quote
Old 12-30-2009, 03:42 PM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Um... there might be some error in your javascript. I'd recommend you to change the type of your button elements to type="button" and then use firebug to get the errors from its console.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
Snitz (12-30-2009)
Old 12-30-2009, 03:44 PM   PM User | #5
Snitz
Regular Coder

 
Join Date: Jul 2004
Location: Lebanon
Posts: 223
Thanks: 6
Thanked 0 Times in 0 Posts
Snitz is an unknown quantity at this point
Quote:
I'd recommend you to change the type of your button elements to type="button"
That worked, thanks mate.
Snitz is offline   Reply With Quote
Old 12-30-2009, 04:14 PM   PM User | #6
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Originally Posted by Snitz View Post
That worked, thanks mate.
Forgot to mention.. after fixing the error, you should revert the type to submit, otherwise your form won't work for those who have no javascript support.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Tags
error, javascript, validation

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:51 PM.


Advertisement
Log in to turn off these ads.