Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2013, 05:36 PM   PM User | #1
oedwards
New to the CF scene

 
Join Date: Jan 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
oedwards is an unknown quantity at this point
Calling multiple XML files depending on what the user clicks on

Hi,

I would like to set up a keyboard style buttons so when a user click on ‘A’ for instance the output from an XML file is displayed in another DIV on the page.

I have achieved the calling of an XML file using JS and displaying the data in another DIV for one letter however I am struggling to work out how to get it to call different XML files based on the letter selected.

I am new to JS and have not yet sat down to learn the fundamentals so I apologise in advance for any acts of a newbie poster. In my head this should be fairly simple and if I were learn JS properly rather than grabbing snippets it would make sense. From what I have read I would need to write an array but am at a loss as how to go about this.

My Code;

From a *.js file

Code:
$(document).ready(function(){
  $("button").click(function(){
    $(".iyc-body-content-main-inner-right-keys-inner-ans").load("xml/knowledge_base_a.xml");
  });
});
From a *.php file

Code:
<button class="keys">a</button>
<button class="keys">b</button>
<button class="keys">c</button>
etc
So there will be the below XML files to call based on what the users clicks on;

clicks on 'A' > xml/knowledge_base_a.xml
clicks on 'B' > xml/knowledge_base_b.xml
clicks on 'C' > xml/knowledge_base_c.xml
etc

As mentioned it currently works for _a.xml but I am unsure how to vary it based on the user click vs the XML file required.

Thank in advance

Hopefully I can give some love back in the CSS/HTML forum.

Ta
Olly

Last edited by oedwards; 01-21-2013 at 05:42 PM..
oedwards is offline   Reply With Quote
Old 01-22-2013, 07:50 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
I am giving you pure javascript for this not jquery as you have. This is how to detect a key press and gets what key was pressed. This code uses an input box, but if you remove the comment on the first js line you will get the alerts if a key is typed anywhere. FYI the anywhere thing does not work in IE, use the box.

Code goes in <body>
Code:
<script type="text/javascript">
//document.onkeyup=displayunicode;

function displayunicode(e){
var unicode=e.keyCode? e.keyCode : e.charCode
//alert(unicode);  // USE THIS TO SEE THE CODES
if (unicode == 65) alert("its an A"); // INSTEAD OF AN ALERT USE THIS TO CALL THE XML
if (unicode == 66) alert("its an B");
if (unicode == 67) alert("its an C");
if (unicode == 68) alert("its an D");
}
</script>

<form>
<input type="text" size="2" maxlength="1" onkeyup="displayunicode(event);" />
</form>
PS: onkeyup and onkeydown are the only things that work.
sunfighter is offline   Reply With Quote
Old 01-22-2013, 10:39 PM   PM User | #3
oedwards
New to the CF scene

 
Join Date: Jan 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
oedwards is an unknown quantity at this point
Thanks for the reply - I will work though and report back. Thanks again
oedwards is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:52 AM.


Advertisement
Log in to turn off these ads.