Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] javascript and forums

Started by GameMasterXL Aug 23, 2005 at 5:25 AM 20 replies 1.5k views
Original Post
GameMasterXL
GameMasterXL
I am creating a script eidtor using &#106avascript, html but i want it so that if you click on different links it calls a different &#106avascript function that will create a html UI with the required events on it in a certain place on my page is this possible? if so how would one go about doing it? thanks.
benryves
benryves
Not sure what you mean, exactly.
To get a hyperlink to call a script function, you can do this:



(For example,
Click!).
If you mean you want to edit the HTML of your page, you can create elements, assign them with an ID then edit their innerHTML property, such as:

THIS IS THE ELEMENT I'M GOING TO CHANGE!

Click to change.

(I had to use an anchor, the forum software doesn't like posting paragraph tags).
If you click "Edit" on my post, you can see the script I used.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
benryves
benryves
Quote:
Original post by Pipo DeClown
omG? That's amazing.

How are you?

You need to escape your single quote. [smile]

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
GameMasterXL
GameMasterXL
Nice is whay i am doing is i want the &#106avascript function to create a UI like buttons and fields that i need with the functions applied to them and the UI gets built on my html page were i want them to go. Is it possible.
benryves
benryves
Yes, seeing as you can set the .innerHTML to anything you want. The forum software on this site strips out &#106avascript or form elements pretty harshly (as you'd expect it to!) so I could not write a demo that added, for example, a submit button.

If you want to attach a &#106avascript function to a normal submit button, set the input type to "button" and add a field called <tt>onclick</tt> which contains the &#106avascript - for example:<br><br><tt>&lt;input type="button" &#111;nclick="alert('Hello')" value="Click me!" name="test_button" /&gt;</tt><br><br>I'm not entirely sure what you're asking, though. Sorry...
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
GameMasterXL
GameMasterXL
Sorry about my vage explanation i will try explain best i can. Is what i am creating is a script editor and in the editor i have a library of commands and for each command i want it so when you click on the link for the command like + command it will create a UI under my text area with the required fields for the user to fill in and then the functions are applied to these controls that will output the value to the main window. So each command has its own unique interface and i want &#106avascript to build the forum in the place i want it to and add the functions to it like creat a text fiel with a button when you press on a link in a specified location.
benryves
benryves
Ah, right. Sounds like a pretty awkward thing to have to write...
I know they're not as slick, but have you considered using prompt() boxes to get user input?
Example
var x = prompt('Enter your variable below:','Enter it here!');if (x===null) {    alert('Cancelled!');} else {    alert(x);}
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
GameMasterXL
GameMasterXL
It wouldn't work for my implimentation. Could i use the innerHtml to create the forums? thanks for your help upto now.
benryves
benryves
You can use innerHTML to edit any HTML on the page, so adding a few form and input elements on a page is not that much of a challenge. It might be more practical to stick the forms inside div elements and show/hide the divs as needed, though.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
GameMasterXL
GameMasterXL
How do i use Divs? so i can position the new form inside of my editor correctly?
benryves
benryves
In your case, it would probably be best to think of them as containers for all your other controls. This might be of some use.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
GameMasterXL
GameMasterXL
How would i tell me &#106avascript UI builder function to create the UI form within the Div?
benryves
benryves
Give the div an id, and use document.getElementById('id_of_your_div').innerHTML to set it.
However, my point of using divs was that you have the HTML for the UI already hard-coded on a number of different div elements, and you show/hide the divs you need based on which interface you wish to present.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
GameMasterXL
GameMasterXL
How would i impliment that so i can id the Divs? the library i am implimenting has 100/200 commands and each needs a UI so could my Divs do that?
benryves
benryves
You can give any element an id with the syntax

Having 100-200 hard coded div elements is probably not a great idea as it could end up making your page file size huge, so maybe stick with the dynamic forms.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
GameMasterXL
GameMasterXL
Are the dynamic forums my original &#106avascript idea? were i woulg get the function to output the correct forum? if so then would i use a dive for that function to place the forum in that is one of my problems i could make the forum output but then i would need the div to ouput the form nice and neat and any size form.
benryves
benryves
No, not forum. Form, no u. I'm now completely at a loss as to what you want...
Are you looking for something like this? (Demos are here).
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
GameMasterXL
GameMasterXL
Yes but instead my command library like:

Sleep
Sleep_until
command n..

So if i click on the link Sleep in my menu it will create a UI under my text area not exact. So my UI goes under it like:



So it will build the UI for every command under the textarea and every command will have its own User Interface and functions applied to it and then that UI will be built under my textarea and the script values output to the textarea.
GameMasterXL
GameMasterXL
I maneged to figure out divs so now do i just make a script that contains multiple functions that all make there won user interface when the user clicks on a link?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.