Forum Moderators: coopster

Message Too Old, No Replies

PHP Help changing the value of an input tag

         

andrewsmd

2:21 pm on Jun 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK all you people out there that are smarter than me I need some assistance. I'm fairly new to JavaScript and I have a problem. I have a form that runs an external php file via JavaScript when the user clicks a checkbox. The php files runs some checks on a few folders and displays output within a JavaScript alert box if needed. However, if all of my if statements check out I want to just display everything is fine, but not in an alert box just on the page. Basically I have a tag that looks like this;
<INPUT type="hidden" class = "message" STYLE="background-color: #339999; border: 0; color: white;" value = "Everything is Fine" />
Now what I want to do is use JavaScript or php (preferred) to change the value of that box to 'text'. Any help is appreciated. Thanks,

eelixduppy

2:58 pm on Jun 12, 2008 (gmt 0)



Do you mean that you want to change the 'value' or that input tag or the 'type'? Also, since you are grabbing the results from an external PHP script with javascript, this is going to have to be changed with javascript, as well. You first need to assign a 'name' or 'id' to this element otherwise you can't do much (easily). So something like this:

<INPUT type="hidden" [b]id="status"[/b] value = "Everything is Fine" />

Then to change the 'value', it would be something like this:


document.getElementById('status').value = "text";

andrewsmd

3:51 pm on Jun 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is exactly what I was looking for. Thanks

andrewsmd

4:01 pm on Jun 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do have another problem now though. Here are my checkbox and hidden text tags,
<input type="checkbox" name="tnBCBS">

<INPUT type="hidden" id = "status" class = "message" STYLE="background-color: #339999; border: 0; color: white;" value = "TN BCBS is good." />

Now when the checkbox is checked I call an external php file with javascript. It runs some checks and if there are any errors it passes a message back to a JavaScript Alert box. I.E. if("a file exists in a certain spot") I echo "alert('Warning the file exists')"; I have a header conent type in php that allows that to run as JavaScript. I tried to echo the
document.getElementById('status').value = "text";
to change the type of the textbox because I only want to do it if one of my php if statements is false. Any suggestions, the error message I receive is document.getElementById('status') has no properties, but it is there. Thanks,

andrewsmd

8:19 pm on Jun 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just in case anyone was wondering this is how I solved the problem. I put in a bunch of empty divs with different names lets say something like <div id = "test"></div> then in my php when the JavaScript would call the php file on the checkbox click the php would echo("document.getElementById('test').innerHTML = 'message'"); Tada! client side programming with php