These guys are really bugging me.
I'm trying to make a script that will get all elements by tag name "input", I then proceed to put a border around them all so they are easy to point out. I have noticed checkboxes do not all much of anything in FireFox. In IE I can get a border and padding etc but FireFox hates me.
Is there anyway I can make the checkbox more noticable? I was thinking about putting in inside of a div with padding and a background but how would I do that if I just have the element by it's id? I'm not a huge fan of JS, but it seems I need to put up with it lol.
Checkboxes
Started by BlaineSch, Nov 07 2009 08:21 AM
20 replies to this topic
#1
Posted 07 November 2009 - 08:21 AM
|
|
|
#2
Posted 07 November 2009 - 10:08 AM
Can't you just give the div around it an id and get it by document.GetElementByID?
#3
Posted 07 November 2009 - 10:26 AM
The user is uploading a HTML file, I am adding a script that will find all the form fields. I can find them already now but I want them to name them all which means they have to identify them, so I am trying to add borders or something around them all.
#4
Posted 07 November 2009 - 12:03 PM
With form fields you mean all fields in a <form> or all <form>s?
#5
Posted 07 November 2009 - 12:10 PM
Form fields as in input, select, textarea. But I'm focusing on checkboxes because all the others allow css backgrounds/borders.
#6
Posted 07 November 2009 - 12:14 PM
Can't you do something like this:
I haven't tried it and I'm not sure it works, it was just a thought.
myField = document.GetElementByID("the_id");
myField.outerHTML = "<div style='Styles here'>" + myField.outerHTML + "</div>";
I haven't tried it and I'm not sure it works, it was just a thought.
#7
Posted 07 November 2009 - 12:16 PM
outerHTML? Exactly what I was looking for buddy!
Like I said, I'm no pro in JS lol, I never knew this existed lol.
+Rep!
Like I said, I'm no pro in JS lol, I never knew this existed lol.
+Rep!
#8
Posted 07 November 2009 - 12:18 PM
If I were you I would try it before being so happy but I think it will work.
I'm not a pro on JS either but I worked with it almost the whole time from lunch to past midnight yesterday :P
Happy to help :D
I'm not a pro on JS either but I worked with it almost the whole time from lunch to past midnight yesterday :P
Happy to help :D
#9
Posted 07 November 2009 - 12:35 PM
Worked perfect in IE but FF it did not, but I found a site that had a neat script to enable it. Also tested in Safari.
outerHTML in Firefox - JavaScript - Snipplr
outerHTML in Firefox - JavaScript - Snipplr
#10
Posted 07 November 2009 - 12:39 PM
Nice :thumbup1:
#11
Posted 07 November 2009 - 01:42 PM
Another issue now...
Lets say I have 3 input checkboxes in the same "td" element. When you call them by tag name the element at place 0 is the 0th element obviously but when I alter it, it moves down to the bottom moving 1 and 2 up, so the 1st element is now the 2nd and when it moves that to the bottom it goes through the last one twice and the second one never.
I tried making an array of id's then going back and changing them, and that worked great, but what if I had text next to a checkbox? The checkbox is appended so it always goes to the bottom.
Lets say I have 3 input checkboxes in the same "td" element. When you call them by tag name the element at place 0 is the 0th element obviously but when I alter it, it moves down to the bottom moving 1 and 2 up, so the 1st element is now the 2nd and when it moves that to the bottom it goes through the last one twice and the second one never.
I tried making an array of id's then going back and changing them, and that worked great, but what if I had text next to a checkbox? The checkbox is appended so it always goes to the bottom.
<style>
div.one {
background: blue;
padding:3px;
}
</style>
<table>
<tr>
<td>API</td>
</tr>
<tr>
<td>
abc
<input type="checkbox" name="helloworld1">
def
<input type="checkbox" name="helloworld2">
ghi
<input type="checkbox" name="helloworld3">
</td>
</tr>
</table>
<script>
function update(id) {
var data = document.getElementById(id); //gets element
var parent = data.parentNode;
var el = document.createElement(parent.tagName); //el
el.appendChild(data);
var newdiv = document.createElement('div'); //objet to surround it
newdiv.className = "one";
newdiv.innerHTML = el.innerHTML+"One";
parent.appendChild(newdiv);
}
var bs = 0;
var data = document.getElementsByTagName("input");
for (var i = 0; i < data.length; i++) {
data[i].id="bsBetavs10"+bs; //gets element
bs++;
}
for(i = 0;i<bs;i++) {
update("bsBetavs10"+i);
}
</script>
#12
Posted 07 November 2009 - 01:54 PM
But their order doesn't change when I'm testing it, or did I get your problem wrong?


Sign In
Create Account



Back to top









