Text Field changes to 'True' on click - and won't pass Var

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Text Field changes to 'True' on click - and won't pass Var

Post by simonmlewis »

I have an odd form.

Code: Select all

<form method='post' action='/a_productedit'>
			<input type='text' name='id' value='2662'>
			<input type='submit' value='Edit 2662'>
			</form>
I'm using "text" instead of hidden just to see the id. But if I click Edit, that field changes to "true" for a split second, and posts "true" to the next page.

Is there a common cause for this? There is no ajax on this page to cause such a change.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Text Field changes to 'True' on click - and won't pass V

Post by Celauran »

Nothing in the code you have posted explains that behaviour. What else is interacting with the form?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Text Field changes to 'True' on click - and won't pass V

Post by simonmlewis »

Nothing. There are no other <form> tags before it. All the <a href> tags have the correct apostrophies and closing </a> tags.

The really odd this is how it changes in the field. Click it... it goes from numeric to the word "true" instantly.

If I put another form above this code, my code works, but then the new code has the same problem, with "true" going in there. Goodness knows why.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Text Field changes to 'True' on click - and won't pass V

Post by simonmlewis »

Damn it, it's this code here:

Code: Select all

    <script type = "text/javascript">
        function Select(obj) {
            obj.className = 'selected';
            obj.getElementsByTagName("input")[0].value = "true";
        }
        function HighLight(obj) {
            if (obj.getElementsByTagName("input")[0].value == "false") {
                obj.className = 'highlight';
            }
        }
        function UnHighLight(obj) {
            if (obj.getElementsByTagName("input")[0].value == "false") {
                obj.className = '';
            }
        }
    </script>
When we click the row, it highlights (on purpose). But it's changing the value of a field too.
And it uses this to highlight the row:

Code: Select all

onclick=\"Select(this);\"
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Text Field changes to 'True' on click - and won't pass V

Post by simonmlewis »

I've changed the script to this:

Code: Select all

    <script type = "text/javascript">
        function Select(obj) {
            obj.className = 'selected';
            
        }
        function HighLight(obj) {
            if (obj.getElementsByTagName("input")[0].value == "false") {
                obj.className = 'highlight';
            }
        }
        function UnHighLight(obj) {
            if (obj.getElementsByTagName("input")[0].value == "false") {
                obj.className = '';
            }
        }
    </script>
Tho oddly, we use this elsewhere on other sites, and it works without flaw.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Text Field changes to 'True' on click - and won't pass V

Post by Celauran »

Code: Select all

obj.getElementsByTagName("input")[0].value = "true";
You may want to refine this a little so it doesn't blindly grab the first input element. I don't know what the criteria should be, understandably, but perhaps adding a class to use as a selector would help.
Post Reply