Click to See Complete Forum and Search --> : generating new page?
hellosamhi
03-03-2004, 09:39 PM
Hello there,
I am very new to Javascript. I am trying to write a page conatining a list (with checkboxes). After certain checkboxes is checked, it will then open (and goes to) a page conatining those checked items. Could someone give me some examples of it? Many Thanks.
Sam
steelersfan88
03-03-2004, 10:06 PM
Try this: )Just make sure only the checkboxes are contained in the form fields, keep the button separate)<form>
... all checkboxes
<input type="checkbox" value="First Checkbox Checked"> First<BR>
<input type="checkbox" value="Second Checkbox Checked"> Second<BR>
<input type="checkbox" value="Third Checkbox Checked"> Third
</form>
<input type="button" onclick="newPgGen()" value="Generate New Page">
<script type="text/javascript">
function newPgGen() {
var myVals = new Array
for(var i=0;i<document.forms[0].elements.length;i++) {
if(document.forms[0].elements[i].checked == true) {
myVals[myVals.length] = document.forms[0].elements[i].value
}
}
var win = window.open('','_blank')
win.document.write('<html><title>Auto Generated</title>')
win.document.write('Checkbox Values Checked:<BR><BR>')
for(var i=0;i<myVals.length;i++) {
win.document.write('<li>'+ myVals[i] +'<BR>')
}
win.document.close()
}
</script>
hellosamhi
03-03-2004, 10:21 PM
Hello steelersfan88
Thank you for the reply. What if I really want is to open an existed page and "insert" those checked items into the new pages? Thanks again.
Sam
steelersfan88
03-04-2004, 06:41 AM
this woul probably be a better alternative, you could probably get away with it if it that page is on your server. Not quite sure how you would want to go about doing that:
Maybe sending each string to the address: (EDIT: After your address, make sure there is a ?)var address = "myserver/checkbox.htm?"
for(var i=0;i<myVals.length;i++) {
address += (Number(i) + 1) +'='+ myVals(i)
if(i != myVals.length - 1) {
address += '&'
}
}Then call the window open to that address.
Then on the page to show the checked boxes, maybe add this script (note probably can be condensed:<script>
var URL = document.location.href
var parts = URL.split("&")
var vals = new Array
for(var i=0;i<parts.length;i++) {
if(i == 0) {
parts[i] = parts[i].substr(parts[i].indexOf('?') +1, parts[i].length)
}
vals[i] = parts[i].substr(parts[i].indexOf('=') +1, parts[i].length)
parts[i] = parts[i].substr(0, parts[i].indexOf('='))
}
if(parts.length == 1 && vals[0] == document.location.href && parts[0] == 0) {
var msg = parts.splice(0,1)
var msg2 = vals.splice(0,1)
}
for(var i=0;i<parts.length;i++) {
document.write(parts[i] +", "+ vals[i] +"<BR>")
}
</script>Which would write the checked checkboxes to the page. (Note, I haven't tested this yet!)
hellosamhi
03-04-2004, 02:12 PM
Thank you steelersfan88!
That helps a lot! Now I have a small question, how do you genterate a new page with a specific name? say "new.html" The 1st javascript you provided generate a new "about:blank" page, is that a way to generate one with a name? Thanks for all your help!
Sam
steelersfan88
03-04-2004, 02:35 PM
change the name to new.html ... yet then anytime the user presses the button for the values, they will get it on the same page, which may be what you are looking for:
window.open('','new.html') // not _blank
hellosamhi
03-04-2004, 02:47 PM
Thank a lot! :)
hellosamhi
03-04-2004, 07:33 PM
Hello there,
I got anotyher question about creating a new page. Say after I generated a new page, could I as it as a certain file name and dump it to a location?
Thanks again.
Sam
steelersfan88
03-04-2004, 07:36 PM
if you mean, (im not sure), storing the value into a file, you are going to need server side, PHP would be good, i don't know how well it (or if it) supports local files though. I know VBScript can use open, but I don't think browsers support it. Where do you want to dump the information, on the server, or locally on their hard drive?
I'm not going to be able to help too much because once PHP gets away from its Javascript similarities ... I don't use it! So if you want, post in the PHP forum, or PM fredmv to move the thread for you! ;)
hellosamhi
03-04-2004, 07:57 PM
Hello steelersfan88,
What I mean is ... say I generate a page "about:blank", then I want to save it (using javascript) straight to C:\temp. Is there a command for that? window.save(new.html) maybe ????
Thanks again.
Sam
steelersfan88
03-04-2004, 08:54 PM
not in javascript, you can try the PHP forum for saving files to hard drive ... i'm pretty sure (not positively) that PHP can do that. If not, its some security restriction ... maybe you'd want to store it in a cookie instead and then read form that if you have no luck!