LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2023, 12:22 AM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 443

Rep: Reputation: 12
Can't call function with results chosen from select list


<

<!-- ==================================================================== -->
<!-- ========================== HTML =============================== -->
<!-- ==================================================================== -->


<!DOCTYPE html>

<html>

<head>
<title>Account Categories</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<!-- ==================================================================== -->
<!-- ========================== STYLES =============================== -->
<!-- ==================================================================== -->

<!--<link rel="stylesheet " type="text/css" href="css/main.css" />
<link rel="stylesheet " type="text/css" href="css/buttons.css" />
<link rel="stylesheet " type="text/css" href="css/frontend.css" />-->


<!-- ==================================================================== -->
<!-- ========================== SCRIPTS =================================== -->
<!-- ==================================================================== -->

<script type="text/javascript" src="../../jquery/jquery-3.2.0.js"></script>

</head>

<!-- ==================================================================== -->
<!-- ========================== BODY =================================== -->
<!-- ==================================================================== -->

<body>

<div id="category">

</div>

<<div id="city">


</div>

<!-- ==================================================================== -->
<!-- ========================== MORE SCRIPTS =================================== -->
<!-- ==================================================================== -->


<!-- ================== CATEGORY - DROPDOWN BOX =================== -->

<script type="text/javascript" >

let mySelection=""; // global var

myAjaxCallCat();

function myAjaxCallCat() {

var request = $.ajax({
url: "getCategory.php",
type: "POST",
//data:
dataType: "json"
});

request.always(function (data) {

$('#category').append($("<br><label for='cats'>Choose a Category</label><br>"))
.append($("<select id='cats' name='cats' size='5' ></select>"))
.append("<br>");

for (const val of data) {
$('#cats').append($("<option>").prop({ value: val, text: val }));
//$('#category').append($("<option>").prop({ value: val, text: val }));
}
//$('#cats').append("<br><br>");

$("#cats").on('change', function () {
mySelection=$("#cats option:selected").text(); // global mySelection

alert("You Chose: "+mySelection); THIS IS WORKING AND DOES SHOW CHOSEN CATEGORY

EVERYTHING BELOW WILL NOT WORK - IT'S IN THE SAME FUNCTION BLOCK SO I'M AT A LOSS AS HOW TO FIX IT - PLEASE HELP

/* myAjaxCallCo(window.mySelection);

function myAjaxCallCo(cat) {
alert("line 97: "+cat);

var request = $.ajax({
url: "getCompany.php",
type: "GET",
data: {"category":cat},
dataType: "json"
});

request.always(function (data) {

alert(data

})
}

*/

}) // cats
})// request
}// myAjaxCall

</script>


</body>
</html>[/CODE]

Last edited by pizzipie; 02-15-2023 at 12:34 AM.
 
Old 02-15-2023, 12:58 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,885
Blog Entries: 1

Rep: Reputation: 1872Reputation: 1872Reputation: 1872Reputation: 1872Reputation: 1872Reputation: 1872Reputation: 1872Reputation: 1872Reputation: 1872Reputation: 1872Reputation: 1872
Kindly edit your post and add [code] and [/code] tags.

Checked the JavaScript Console in Web Developer Tools? I bet there's a few errors/warnings there.

Edit: Might it be because of the /* and */ symbols?

Last edited by NevemTeve; 02-15-2023 at 01:37 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
-current, list of services to start, chosen during install slvr32 Slackware 2 11-16-2021 08:34 AM
gprof results displays always 0.0 for function call time udaykumar84 Programming 1 04-26-2012 03:53 AM
Bash/Perl script - provide list of hosts to choose from and ssh to chosen host loadedmind Programming 4 04-07-2010 01:19 PM
[SOLVED] Threaded function cannot call a function with extern "C" but nonthreaded function can morty346 Programming 16 01-12-2010 05:00 PM
Question on using select() function call with FIFO Sathya Programming 12 05-30-2008 09:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration