School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,477 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,766 people online right now. Registration is fast and FREE... Join Now!




Variable and getElementById.src help

 

Variable and getElementById.src help

dreadfear

19 Jun, 2009 - 05:14 PM
Post #1

D.I.C Head
**

Joined: 8 Dec, 2008
Posts: 166



Thanked: 1 times
My Contributions
CODE
function formsubmit(){
var correct = document.getElementById('un').src = "http://www.gibboes.com/tristan/images/correct.GIF";
var incorrect = document.getElementById('un').src = "http://gibboes.com/tristan/images/incorrect.GIF";
var blank = document.getElementById('un').src = "http://gibboes.com/tristan/images/blank.GIF";
var x=document.getElementById('signup');
var username = document.getElementById("username").value;
var ui = username.length;
var password = x.password.value;
var pi = password.length;
var conpassword = x.confirmedpass.value;
var cpi = conpassword.length;
var email = x.email.value;
if (ui > 6 && ui < 12){
correct;
}
else{
incorrect;
}
if (pi > 6 && pi < 20){

}
else{
}
if (conpassword == password){

}
else{

}
alert(username);
}code]


CODE
<?php
include("connect.php");
echo("<forms id='signup' action='register.php'>
Username:<input type='text' name='username'><img id='un' width='10' height='10' /><br/>
Password:<input type='password' name='password'><br/>
Confirm Password:<input type='password' name='confirmedpass'><br/>
Email:<input type='text' name='email'><br/>
Confirm Email:<input type='text' name='confirmemail'><br/>
<input type='submit' name='signup' value='By clicking accept you agree to the terms and conditions' onclick='formsubmit();'>
</forms>");
?>


Now im trying to change the image next to the username textbox, the code im using now works within reason.

It changes the image, but it always changes the image to correct.GIF even when it shouldnt

Also the alert box doesnt appear

What am i doing wrong here?
Thanks in advance

This post has been edited by dreadfear: 19 Jun, 2009 - 06:26 PM

User is offlineProfile CardPM
+Quote Post


roudard

RE: Variable And GetElementById.src Help

20 Jun, 2009 - 01:35 AM
Post #2

D.I.C Head
**

Joined: 26 Sep, 2005
Posts: 139



Thanked: 16 times
My Contributions
hey,

those 3 lines are wrong :
CODE
var correct = document.getElementById('un').src = "http://www.gibboes.com/tristan/images/correct.GIF";
var incorrect = document.getElementById('un').src = "http://gibboes.com/tristan/images/incorrect.GIF";
var blank = document.getElementById('un').src = "http://gibboes.com/tristan/images/blank.GIF";


your script just errors after it assigned correct.gif as the src of the image

keep it simple:
CODE

function formsubmit(){

var x=document.getElementById('signup');
var username = document.getElementById("username").value;
var ui = username.length;
var password = x.password.value;
var pi = password.length;
var conpassword = x.confirmedpass.value;
var cpi = conpassword.length;
var email = x.email.value;
if (ui > 6 && ui < 12){
document.getElementById('un').src = "http://www.gibboes.com/tristan/images/correct.GIF";

else{
document.getElementById('un').src = "http://gibboes.com/tristan/images/incorrect.GIF";
}
if (pi > 6 && pi < 20){

}
else{
}
if (conpassword == password){

}
else{

}
alert(username);
}




haven't tested it, but it should work

hope this helps


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:37AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month