PDA

View Full Version : Highlight form element



Comex
03-19-2011, 02:54 AM
Hello,

Using a link bid script that uses script from here:

http://www.dynamicdrive.com/dynamicindex11/highlightform.htm

Add it is used for the dropdown.

Example:

http://constructionbannerexchange.com/directory/submit.php?su_categ=

When you try to scroll and choose a catagory it dose Not allow you to do so.

You would have to use arrow keys and users may not to be able to figure this out or just find it annoying.

Is there a way to fix this issue? The linkbid admin dose Not have the answer.

Thank you!

jscheuer1
03-19-2011, 06:08 AM
In future, please post about Dynamic Drive Scripts in the Dynamic Drive Scripts Help section here where I've moved this.

The script is buggy as regards selects, especially in IE, but also to a lesser extent in others. I'd suggest removing them from the list. Change:


//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

to:


//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA/


As a side note, if onfocus is used instead of onkeyup and onclick, things improve. However, at that point the event must be applied directly to the element, using the form no longer works, so things get complicated. And they are still not ideal, the first click in IE doesn't drop down the list.

But you can try it out if you like. Use this modified version of the script:


<script type="text/javascript">

//Highlight form element- Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

var highlightcolor="green"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj) || e.type === 'focus')
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj) || e.type === 'focus')
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}

</script>

And add this onfocus event to any select:


<select name="selectc" id="selectc" onfocus="highlight(event);">

This approach may have other problems though.

Comex
03-20-2011, 05:07 PM
Very Nice: THANKYOU!

The http://constructionbannerexchange.com/directory/submit.php?su_categ=


is Now perfect.

I tried to use the same html for contact page but recieved the following when I applied:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/63/7572563/html/directory/contact.php:1) in /home/content/63/7572563/html/directory/contact.php on line 1




http://constructionbannerexchange.com/directory/contact.php

jscheuer1
03-21-2011, 02:52 AM
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/63/7572563/html/directory/contact.php:1) in /home/content/63/7572563/html/directory/contact.php on line 1

That's a server side PHP error and probably means exactly what it says - That a cache limiter should be sent before the headers. Check the PHP code, or perhaps it was a fluke.

In any case, changing the javascript should have no impact on that. If it wasn't a fluke, somehow the PHP code got changed, perhaps by working from an older version of the page. But it could have been anything.

djr33
03-21-2011, 04:10 AM
For sessions to work in PHP, the session_start() function MUST be called before any output of any kind. It must send a header, so if the headers are already sent (this happens once) then the session won't get started, and you get that error.
This may or may not have anything to do with the script problems. It certainly not caused by the script though: this is a problem with the parsing of the PHP file, before any Javascript can execute.